package com.leapp.sk.viewdelegate.archives

import android.content.Context
import android.content.Intent
import android.text.TextUtils
import android.widget.ListView
import com.example.mvp.delegate.BaseAppDelegate
import com.example.mvp.view.SKTopBar
import com.leapp.sk.R
import com.leapp.sk.bean.BabyAchivesEntity
import com.leapp.sk.ui.activity.archives.BabyArchivesActivity
import com.leapp.sk.ui.activity.join.SearchClassActivity
import com.leapp.sk.ui.adapter.BabyArchivesAdapter
import com.example.util.finallist.IS_BABY_ARCHIVES

/**
 * 宝贝档案视图托管类
 * @author  chaohaipeng  on 2018/8/7.
 */
class BabyArchivesDelegate :BaseAppDelegate(){
    /**
     * 适配器
     */
   var babyArchivesAdapter:BabyArchivesAdapter?=null

    override fun initWidget() {
    }
    override fun initLayoutRes(): Int {
        return R.layout.activity_baby_archives
    }

    /**
     * 初始化适配器
     */
    fun initAdapter(context: Context, mlist: List<BabyAchivesEntity>){
       val lv_aba_list=getView<ListView>(R.id.lv_aba_list)
        babyArchivesAdapter = BabyArchivesAdapter(context, mlist)
        lv_aba_list.adapter=babyArchivesAdapter

        lv_aba_list.setOnItemClickListener{adapterView, view, i, l ->
            run {
                val intent: Intent = Intent(getActivity(), SearchClassActivity::class.java)
                intent.putExtra(IS_BABY_ARCHIVES,true)
                getActivity<BabyArchivesActivity>().startActivity(intent)
            }
        }

    }

    /**
     * 刷新适配器
     */
    fun notifyAdapter(){
        babyArchivesAdapter?.notifyDataSetChanged()


    }


    /**
     * 设置标题
     */
    fun setTitle(title:String?){
        val topBar= getView<SKTopBar>(R.id.jtb_aba)
        if (!TextUtils.isEmpty(title)){
            topBar?.setTitle(title)
        }
        setEvent(topBar)
    }
    /**
     * 设置设置事件
     */
    private  fun setEvent(topBar: SKTopBar){
        topBar?.setEventInterface(object : SKTopBar.EventInterface{
            override fun leftOnClick() {
                getActivity<BabyArchivesActivity>().finish()

            }
            override fun rightOnClick() {
            }

        })
    }
}